package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_VALUE;

public class TemplateArgument extends NamedElement {

  public TemplateArgument() {
    this(null, null);
  }

  public TemplateArgument(String name, String value) {
    super(name);
    setValue(value);
    destructable = false;
    preserved = true;
  }

  @Override
  public Object clone() 
    throws CloneNotSupportedException {
    TemplateArgument p = (TemplateArgument) super.clone();
    p.setValue(value);
    return p;
  }

  public String getValue() {
    return value;
  }

  public void setValue(String value) {
    this.value = value;
    setAttribute(ATTR_VALUE, value);
  }

  @Override
  public String toString() {
    return (name + "->" + value);
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (o instanceof TemplateArgument) {
      TemplateArgument e = (TemplateArgument) o;
      if (name == null && e.name != null || 
	  name != null && !name.equals(e.name)) {
	return false;
      }
      if (value == null && e.value != null || 
	  value != null && !value.equals(e.value)) {
	return false;
      }
      return true;
    }
    return false;
  }

  @Override
  public int hashCode() {
    int c = 0;
    if (name != null) {
      c += (name.hashCode() & 0xFFFF0000);
    }
    if (value != null) {
      c += (value.hashCode() & 0xFFFF);
    }
    return c;
  }

  protected String value = null;

}
